<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<s:url value="/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery-1.3.2.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.bgiframe.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.ajaxQueue.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/thickbox-compressed.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.autocomplete.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/tableSel.js"/>"></script>
			<script type='text/javascript'
			src="<s:url value="/js/common.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/jquery.autocomplete.css"/>" />
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/thickbox.css"/>" />
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript"
			src="<s:url value="/js/jquery.blockUI.js"/>"></script>
		<script type="text/javascript">
		function dosubmit(){
		    $('#listForm').submit();
		}
		function changedisplay(el){
			el.toggle("fast",function() {
				 //$Container.getContainerProxy().resize();
			});
		}
		function goAddNew(){
			location.href='<s:url value="/customer/Visit/edit"/>';
		};
		function doShowAll(form){
			form = document.getElementById('listForm');
			var ids = getSelectionIds('a');
			if(ids.length<1){
				alert('Please select one at least.');
			}else{
				$('#dialog').dialog('open');
				
			}
		};
		//新加一个学生
        function doAddStudent(){
              var  sid=  $("#selstudentid").val();
		      var  sn= $("#selstudentName").val();
		      var  st= $("#selstudentTel").val();
		      var  ss= $("#selstudentStatus").val();
		      if (!sid||!sn){
	             alert("please select one student");
	             return;
	          };
	          $('#studentTable').append("<tr id='"+sid+"'></tr>");
			  $("#studentTable")
						.find("tr:last")
						.append("<td class=\"tablecolour2\">"
								+"<input type=\"checkbox\" name=\"a\" value=\""
								 +sid+"\"/></td><td class=\"tablecolour2\">" 
							    + sn+ "</td><td class=\"tablecolour2\">"
							    + st+ "</td><td class=\"tablecolour2\"></td>"
							    + "<td class=\"tablecolour2\"></td>"
							    + "<td class=\"tablecolour2\"></td>"
							     + "<td class=\"tablecolour2\"></td>"
							    + "<td class=\"tablecolour2\"></td><td class=\"tablecolour2\">"
							    + ss+"</td><td class=\"tablecolour2\"  style=\"cursor:pointer\""
									+ "  onclick=\"doDeleteStudent('"
									+ sid + "');\">Del</td>");
        };
        function doDeleteStudent(clsId){
	    	   $("#"+clsId).remove();
		};
		$(document).ready(function(){
		if ($.trim($('#result').text()) != '') {
			popupDiv('pop-div');
		};
		$('#dialog').hide();
		$('#dialog').dialog({
			bigiframe:true,
			autoOpen:false,
			modal:true,
			buttons:{
				'Show Up':function(){
			form = document.getElementById('listForm');
			form.action=form.action.replace('list','showAll');
			var ids = getSelectionIds('a');
			$('#ids').val(ids);
			$('#suc').val($('#showUpComments').val());
			form.submit();
			},
			'Cancel':function(){
				$('#dialog').dialog('close');
				$(this).dialog('close');
				}
			}

			});
			$('#dialog2').hide();
			$('#dialog2').dialog({
				bigiframe:true,
				autoOpen:false,
				modal:true,
				buttons:{
					'Unshow':function(){
						form = document.getElementById('listForm2');
						
						$('#suc2').val($('#showUpComments2').val());
						form.submit();
					},
					'Cancel':function(){
						$('#dialog2').dialog('close');
						$(this).dialog('close');
					}
				}
			});
		    $('#selCreateStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selCreateEndTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selLastTouchStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selLastTouchEndTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selSetApptStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selSetApptEndTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selShowStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selShowEndTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selAssignTmStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selAssignTmEndTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selInitVisitStartTime').datepicker( {dateFormat :'yy-mm-dd'});
		    $('#selInitVisitEndTime').datepicker( {dateFormat :'yy-mm-dd'});
            $("#selMarketingPlan").autocomplete("<s:url value="/marketing/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
            $("#selMarketingPlan").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selMarketingPlanId").val(d.id);
            });
            $("#selAdChannel").autocomplete("<s:url value="/data/AdChannel/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
            $("#selAdChannel").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selAdChannelId").val(d.id);
            });
            $("#selPTE").autocomplete("<s:url value="/data/PTE/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name+" "+d.wno;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name+" "+d.wno;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
            $("#selPTE").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selPTEId").val(d.id);
            });
              $("#selTM").autocomplete("<s:url value="/system/User/autoCompleteTMAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name+" "+d.wno;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name+" "+d.wno;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
             $("#selTM").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selTMId").val(d.id);
            });
               $("#selPTELead").autocomplete("<s:url value="/data/PTE/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
            $("#selPTELead").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selPTELeadId").val(d.id);
            });
            $("#selCreateUser").autocomplete("<s:url value="/system/User/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      var d=eval("("+row+")");
			      return  d.name;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return d.name;
		      },
		      formatResult: function(row) {
		         var d=eval("("+row+")");
			     return d.name;
     	       }
            });
            $("#selCreateUser").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selCreateUserId").val(d.id);
            });
            $("#selstudent").autocomplete("<s:url value="/customer/Leads/autoCompleteAjax.action"/>", {
               width: 300,
               minChars:2, //几个字
               mastMatch:true,
               selectFirst: false,
               max:  20,
           	   formatItem: function(row, i, max) {
           	      //alert(row);
           	      var d=eval("("+row+")");
           	      //alert(d);
			      return  d.name+ " " + d.tel;
	          },
		      formatMatch: function(row, i, max) {
		         var d=eval("("+row+")");
 			     return  d.name+ " " + d.tel;
		      },
		      formatResult: function(row) {
		        // alert(row);
		         var d=eval("("+row+")");
			     return d.name+" "+ d.tel ;
     	       }
            });
            $("#selstudent").result(function(event, data, formatted) {
           	      var d=eval("("+data+")");
		          $("#selstudentid").val(d.id);
		          $("#selstudentName").val(d.name);
		          $("#selstudentTel").val(d.tel);
		          $("#selstudentStatus").val(d.status);
            });
        });
       	function goDetail() {
			   var sid=$("#selstudentid").val();
			   if (!sid){
			      alert("please select a  student ");
			      return ;
			   }
		 	   var url="<%=basePath%>customer/PersonalTouch/visitEdit?id="+sid;
		 	   var aa=window.open(url);  
	    };
	   function goView(id) {
			   var url="<%=basePath%>customer/PersonalTouch/visitEdit?id="+id;
		 	   var aa=window.open(url);  
	    };
	    function doExport(obj){
		    form = document.getElementById('listForm');
			var tmp =	form.action ;
			form.action = form.action.replace('list','export');
			form.submit();
			form.action = tmp;
	    }
		</script>
		<title><s:text name="system.title" />
		</title>
	</head>
	<body>
		<s:include value="/common/up.jsp"></s:include>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="box">
					<s:form action="Visit/list" name="listForm" id="listForm"
						namespace="/customer">
						<input type="hidden" id="startIndex" name="startIndex" value="0" />
						<s:hidden name="ids" id="ids" />
						<s:hidden name="suc" id="suc" />
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="searchbg">
							<tr>
								<td>
									Name :
									<s:textfield  id="selName"  size="4" name="name" />
									&nbsp;Tel:
									    <s:textfield  id="selTelephone" size="8" name="telephone" />
									&nbsp;Status:
									<s:select id="selLeadsStatus" name="leadsStatus"
										listKey="name()" headerKey="" headerValue="--all--"
										list="@com.ef.constant.ELeadsStatus@values()"></s:select>
									<img src="<s:url value="/img/right/btns.gif"/>" border="0"
										style="cursor: pointer" align="absmiddle"
										onclick="javascript:dosubmit();" />
									<img src="<s:url value="/img/right/btn-s2.gif"/>" border="0"
										style="cursor: pointer" align="absmiddle"
										onclick="javascript:changedisplay($('#div1'));" />
									<img src="<s:url value="/img/right/btn4.gif"/>" border="0"
										style="cursor: pointer" align="absmiddle"
										onclick="javascript:reset2();" />
									<img onclick="javascript:goAddNew();"
										src="<s:url value="/img/right/btn1.gif"/>" border="0"
										align="absmiddle" />
									<img onclick="javascript:doShowAll();"
										src="<s:url value="/img/right/show.gif"/>" border="0"
										align="absmiddle" />
									<img onclick="doExport(this);" src="<s:url value="/img/right/Export.gif"/>" border="0" align="absmiddle" id="exportimg" /> 
								</td>
								</tr>
								<tr>
								<td>
									Leads:
									<s:textfield id="selstudent" size="10" name="selstudent" />
									<s:hidden id="selstudentid" name="selstudentid" />
									<input type="hidden" id="selstudentName" name="selstudentName" />
									<input type="hidden" id="selstudentTel" name="selstudentTel" />
									<input type="hidden" id="selstudentStatus"
										name="selstudentStatus" />
									<img src="<s:url value="/img/right/Detail.gif"/>" border="0"
										onclick="javascript:goDetail();" align="absmiddle" />
									<img onclick="javascript:doAddStudent();"
										src="<s:url value="/img/right/Add.gif"/>" border="0"
										align="absmiddle" />
								</td>
							</tr>
						</table>
						<div id='div1' style="display: none;">
							<table width="100%" border="0" cellpadding="0" cellspacing="0"
								bgcolor="#E0F5FF">
								<!-- tr>
									<td height="40">
										
										&nbsp;Source:
										<s:select id="selLeadsSource" name="leadsSource"
											listKey="name()" headerKey="" headerValue="--all--"
											list="@com.ef.constant.ELeadsSource@values()"></s:select>
										&nbsp;Type:
										<s:select id="selLeadsType" name="leadsType" listKey="name()"
											headerKey="" headerValue="--all--"
											list="@com.ef.constant.ELeadsType@values()"></s:select>
										&nbsp;Ad Channel:
										<s:textfield id="selAdChannel" name="adChannel.name"
											cssClass="input2" size="13" />
										<s:hidden id="selAdChannelId" name="adChannel.id" />
									</td>
								</tr>
								<tr>
									<td height="40">
										&nbsp;MarketingPolicy:
										<s:select id="selMarketingPolicy" name="marketingPolicy.id"
											headerKey="" headerValue="--all--" list="marketingPolicyList"></s:select> 
										&nbsp;PTE Lead:
										<s:textfield id="selPTELead"  name="pteLeader.name" cssClass="input2" size="13" />
										<s:hidden id="selPTELeadId" name="pteLeader.id"/>
									    &nbsp;PTE:
										<s:textfield id="selPTE"  name="pte.name" cssClass="input2" size="13" />
										<s:hidden id="selPTEId" name="pte.id"/>
										&nbsp;Init Visit Time:
										<s:textfield  id="selInitVisitStartTime" name="selInitVisitStartTime" cssClass="input2" size="13" />-
										<s:textfield  id="selInitVisitEndTime" name="selInitVisitEndTime" cssClass="input2" size="13" /> 
									</td>
								</tr>
								<tr>
									<td height="40">
										&nbsp;CreateUser:
										<s:textfield id="selCreateUser" name="createUser.name"
											cssClass="input2" size="10" />
										<s:hidden id="selCreateUserId" name="createUser.id" />
										&nbsp;CreateTime:
										<s:textfield id="selCreateStartTime" name="selCreateStartTime"
											cssClass="input2" size="10" />
										-
										<s:textfield id="selCreateEndTime" name="selCreateEndTime"
											cssClass="input2" size="10" />
										&nbsp;TM :
										<s:textfield  id="selTM" name="tm.name" cssClass="input2" size="10" /> 
										<s:hidden id="selTMId" name="tm.id"/>
										&nbsp;TmAssign Time:
										<s:textfield id="selAssignTmStartTime"
											name="selAssignTmStartTime" cssClass="input2" size="10" />
										-
										<s:textfield id="selAssignTmEndTime" name="selAssignTmEndTime"
											cssClass="input2" size="10" />
									</td>
								</tr -->
								<tr>
									<td height="40">
										&nbsp;LastTouchTime:
										<s:textfield id="selLastTouchStartTime"
											name="selLastTouchStartTime" cssClass="input2" size="10" />
										-
										<s:textfield id="selLastTouchEndTime"
											name="selLastTouchEndTime" cssClass="input2" size="10" />
										&nbsp;SetApptTime:
										<s:textfield id="selSetApptStartTime"
											name="selSetApptStartTime" cssClass="input2" size="10" />
										-
										<s:textfield id="selSetApptEndTime" name="selSetApptEndTime"
											cssClass="input2" size="10" />
										&nbsp;Show Time:
										<s:textfield id="selShowStartTime"
											name="selShowStartTime" cssClass="input2" size="10" />
										-
										<s:textfield id="selShowEndTime" name="selShowEndTime"
											cssClass="input2" size="10" />
									</td>
								</tr>
							</table>
						</div>
						<table width="100%" border="0" id="studentTable" cellpadding="0"
							cellspacing="1" class="box2">
							<tr>
								<td width="33" class="tablecolour1">
									<input type="checkbox" name="all" onclick="checkAll('a',this)" />
								</td>
								<td class="tablecolour1" >
									Name
								</td>
								<td class="tablecolour1" >
									Telephone
								</td>
								<td class="tablecolour1" >
									Leads Source
								</td>
								<td class="tablecolour1" >
									TM/CC
								</td>
								<td class="tablecolour1">
									TouchTime
								</td>
								<td class="tablecolour1"  nowrap="nowrap" >
									Last Comments
								</td>
								<td class="tablecolour1"  nowrap="nowrap">
									ShowUp Comments
								</td>
								<td class="tablecolour1" >
									Show Time
								</td>
								<td class="tablecolour1" >
									Status
								</td>
								<td class="tablecolour1" >
									Function
								</td>
							</tr>
							<s:set name="oldShowCode" value="%{'0'}"></s:set>
							<s:set name="oldTdClass" value="%{'tablecolour1'}"></s:set>
							<s:iterator value="listResult.items" status="status">
							    <s:if test="%{#oldShowCode!=showCode}">
							         <s:if test="%{#oldTdClass=='tablecolour1'}">
							            <s:set name="oldTdClass"  value="%{'tablecolour2'}"></s:set>
							         </s:if>
							         <s:else>
							            <s:set name="oldTdClass"  value="%{'tablecolour1'}"></s:set>
							         </s:else>
							    </s:if>
							    <s:set name="oldShowCode"  value="showCode"></s:set>
								<tr>
									<td class="<s:property value="#oldTdClass"/>">
										<s:set name = "e" value="@com.ef.constant.ELeadsStatus@values()[11]" />
										<s:set name = "e2" value="@com.ef.constant.ELeadsStatus@values()[12]" />

										<input type="checkbox" name="a" value="<s:property value="id"/>" <s:if test="leadsStatus==#e||leadsStatus==#e2" >disabled</s:if>/>
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:property value="name" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:property value="mobileTelephone" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:property value="leadsSource" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:property value="tm.name" />/<s:property value="cc.name" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:date name="lastEventTime" format="yyyy-MM-dd HH:mm" />
									</td>
									<td class="<s:property value="#oldTdClass"/>">
										<s:property value="lastEventCommons" />
									</td>
									<td class="<s:property value="#oldTdClass"/>">
										<s:property value="showUpComments" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:date name="showTime" format="yyyy-MM-dd" />
									</td>
									<td class="<s:property value="#oldTdClass"/>"  nowrap="nowrap">
										<s:property value="leadsStatus" />
									</td>
									<td class="<s:property value="#oldTdClass"/>" nowrap="nowrap">
										<s:set name = "e4" value="@com.ef.constant.ELeadsStatus@values()[11]" />
										<s:if test="leadsStatus==#e4">
										<a href='#' onclick="$('#id').val('<s:property value="id"/>');$('#dialog2').dialog('open');">Unshow</a>
									    </s:if>
										<a
											href='#' onclick="goView('<s:property value="id"/>')">View</a>
									</td>
								</tr>
							</s:iterator>
						</table>
						<s:include value="/common/page.jsp"></s:include>
						<div id="dialog" >
						 ShowUp Comments:<br />
						 		 <s:textarea name="showUpComments" id="showUpComments" rows="4" cols="40"></s:textarea>
						</div>
						<div id="dialog2" >
						 Unshow Comments:<br />
						 		 <s:textarea name="showUpComments2" id="showUpComments2" rows="4" cols="40"></s:textarea>
						</div>
					</s:form>
					<s:form action="Visit/unshow" name="listForm2" id="listForm2"
						namespace="/customer">
						<s:hidden name="id" id="id" />
						<s:hidden name="suc2" id="suc2" />
					</s:form>
				</td>
			</tr>
		</table>
		<s:include value="/common/down.jsp"></s:include>
		<div id='pop-div' style="width: 300px;" class="pop-box">
			<s:include value="/common/confirm.jsp"></s:include>
		</div>
	</body>
</html>